<?php

interface database
{	  
	public function __construct($db_host, $db_user, $db_pass, $db_db, $app);
	public function connect();
	public function switch_db($db);
	public function query($query);
	public function insertid($query);
	public function num_rows($res);
	public function fetch_assoc($res);
	public function free_result($res);
	public function get_type();
	public function real_escape($str);
}


class mysql_database implements database
{
	var $link_var;
	  
	var $host;
	var $user;
	var $pass;
	var $db;
	var $app;
	  
	function get_type()
	{
		return "mysql";
	}
	
	function __construct($db_host, $db_user, $db_pass, $db_db, $app)
	{
		$this->host = $db_host;
		$this->user = $db_user;
		$this->pass = $db_pass;
		$this->db = $db_db;
		$this->app =& $app;
	}
	  
	function connect()
	{
		$this->link_var = mysql_connect($this->host, $this->user, $this->pass);
		if (!$this->link_var)
			return false;
		$this->switch_db($this->db);
			return true;
	}
	  
	function switch_db($db)
	{
		return mysql_select_db($db, $this->link_var);
	}
		  
	function query($query)
	{
		$res = mysql_query($query, $this->link_var);
		if (!$res)
		{
			$this->app->error("Error executing query- Error: " . mysql_error() . "<Br>Query: $query<br>");
		}
		return $res;
	}
		  
	function insertid($query)
	{
		$this->query($query);
		return mysql_insert_id($this->link_var);
	}
	
	function num_rows($res)
	{
		return mysql_num_rows($res);
	}
	
	function fetch_assoc($res)
	{
		return mysql_fetch_assoc($res);
	}
	
	function free_result($res)
	{
		return mysql_free_result($res);
	}

	function real_escape($str)
	{
		return mysql_real_escape_string($str, $this->link_var);
	}
}


?>